combinatorics dp math *1700

Please click on ads to support us..

C++ Code:

/*

懒猫点灯第一百一十三天



dp[i][0] = dp[i-1][1] + dp[i-2][1]

dp[i][1] = dp[i-1][0] + dp[i-2][0]



dp[i] = dp[i-1] + dp[i-2]

*/

#include<bits/stdc++.h>

using namespace std ;

#define ll long long

const ll N = 2e6+9 ;

const ll mod = 1e9+7 ;

const ll MAXN = 0x3f3f3f3f ;

ll Min( ll a , ll b ){ return a>b?b:a ; }

ll Max( ll a , ll b ){ return a>b?a:b ; }

ll Abs( ll x ){ return x>0 ? x : -x ; }

//gcd(a,b)=gcd(b,a)=gcd(-a,b)=gcd(|a|,|b|)=gcd(b,a mod b)

//ax+by = gcd(a, b) =d

ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}

ll ksm( ll a , ll b ){

    ll res = 1 ;

    while( b > 0 ){

        if( b&1 ) res = res * a % mod ;

        b >>= 1 ;

        a = a*a % mod ;

    }

    return res ;

}

ll dp[ N ] ;

void solve(){

    ll n , m ; cin >> n >> m ;

   dp[ 1 ] = 2 ; dp[ 2 ] = 4 ;

   for( int i = 3 ; i <= Max(n,m) ; i ++ ){

        dp[i] = (dp[i-1] + dp[i-2])%mod ;

   }



   cout << ( dp[n] + dp[m] - 2 + mod )%mod << "\n" ;



   return ;

}

int main(){

    ios::sync_with_stdio(false) ; cin.tie(0) ;

    ll t = 1 ; //cin >> t ;

    while( t-- ) solve() ;

return 0 ;

}

/*

10 1

5 1 2 3 6 9 7 8 11 12

*/


Comments

Submit
0 Comments
More Questions

1511C - Yet Another Card Deck
1698A - XOR Mixup
1702E - Split Into Two Sets
1703B - ICPC Balloons
1702F - Equate Multisets
1700A - Optimal Path
665C - Simple Strings
1708A - Difference Operations
1703E - Mirror Grid
1042A - Benches
1676B - Equal Candies
1705B - Mark the Dust Sweeper
1711A - Perfect Permutation
1701B - Permutation
1692A - Marathon
1066A - Vova and Train
169B - Replacing Digits
171D - Broken checker
380C - Sereja and Brackets
1281B - Azamon Web Services
1702A - Round Down the Price
1681C - Double Sort
12A - Super Agent
1709A - Three Doors
1680C - Binary String
1684B - Z mod X = C
1003A - Polycarp's Pockets
1691B - Shoe Shuffling
1706A - Another String Minimization Problem
1695B - Circle Game